﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.OracleClient;

namespace DBDataAccessLib
{
    public abstract class DBHelperFactory
    {
        public static readonly string Prefix;
        public static readonly DBType DbName;

        static DBHelperFactory()
        {
            string db = ConfigurationManager.AppSettings["DBName"];
            if (db == "SQLSERVER")
            {
                DbName = DBType.SqlServer;
                Prefix = "@";
            }
            else if (db == "ORACLESERVER")
            {
                DbName = DBType.Oracle;
                Prefix = ":";
            }
            else throw new Exception("服务器未知！");
        }

        public static SqlParameter[] ConvertSqlParameterArr(List<DbParameter> parameters)
        {
            SqlParameter[] paras = new SqlParameter[parameters.Count];
            for (int i = 0; i < parameters.Count; i++)
            {
                paras[i] = parameters[i] as SqlParameter;
            }
            return paras;
        }

        public static OracleParameter[] ConvertOracleParameterArr(List<DbParameter> parameters)
        {
            OracleParameter[] paras = new OracleParameter[parameters.Count];
            for (int i = 0; i < parameters.Count; i++)
            {
                paras[i] = parameters[i] as OracleParameter;
            }
            return paras;
        }
    }

    public enum DBType
    {
        Oracle,
        SqlServer,
    }
}
